import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from "@/components/Login";
import Home from "@/components/Home";
Vue.use(VueRouter)
import Welcome from "@/components/Welcome";
import Users from "@/components/Users";
import Rights from "@/components/power/Rights";
import Roles from "@/components/power/Roles";
import List from "@/components/Needs/List";
import Add from "@/components/Needs/Add";
import Order from "@/components/order/Order";
const routes = [
  {
    path: '/',
    redirect:'/login'
  },
  {
    path:'/login',
    component:Login,
     meta: {
        title: ' Group1832作业'   // 标题设置
      }

  },
      {
    path:'/home',
    component:Home,
        redirect: '/welcome',
        children:[{
    path:'/welcome',
          component:Welcome,
          meta: {
        title: ' Group1832作业'   // 标题设置
      }
        },{
    path: '/users',
    component: Users,
          meta: {
        title: ' Group1832作业'   // 标题设置
      }
  },{
    path: '/rights',
    component: Rights,
          meta: {
        title: ' Group1832作业'   // 标题设置
      }
  },{
    path: '/roles',
    component: Roles,
          meta: {
        title: ' Group1832作业'   // 标题设置
      }
  },{
        path: '/goods',
        component: List,
          meta: {
        title: ' Group1832作业'   // 标题设置
      }
      },{
        path: '/goods/add',
        component: Add,
          meta: {
        title: ' Group1832作业'   // 标题设置
      }
      },{
        path: '/orders',
        component: Order,
          meta: {
        title: ' Group1832作业'   // 标题设置
      }
      }]
  },

]
const router = new VueRouter({
  routes
})
router.beforeEach((to,from,next)=>{
   to.meta.title && (document.title = to.meta.title);
  if(to.path==='/login'){return next()}
  const toknstr=window.sessionStorage.getItem('token')
  if(!toknstr){next('/login')}
  next()
})

export default router
